//
// Copyright (c) 2007 Jaepil Jeong
// http://www.springcat.net/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#ifndef __BaseCat_Network_Acceptor__
#define __BaseCat_Network_Acceptor__

#include "NetworkBase.h"
#include "NetworkHandles.h"
#include <BaseCat/System.h>

namespace BaseCat
{
    namespace Network
    {
        namespace Acceptor
        {
            typedef void (__stdcall *Event)(Handle, Link::Handle, void *);

            NETWORK_API Handle __stdcall CreateHandle(System::ThreadPool::Handle threadPool);
            NETWORK_API Handle __stdcall CreateHandle(System::ThreadPool::Handle threadPool, FilterChain::Handle filterChain);
            NETWORK_API void __stdcall DestroyHandle(Handle acceptor);

            NETWORK_API bool __stdcall Start(Handle acceptor);
            NETWORK_API bool __stdcall Stop(Handle acceptor);

            NETWORK_API bool __stdcall SetDefaultPort(Handle acceptor, unsigned short port);
            NETWORK_API bool __stdcall SetDefaultPort(Handle acceptor, unsigned short port, bool reuse);
            NETWORK_API unsigned short __stdcall GetDefaultPort(Handle acceptor);

            NETWORK_API bool __stdcall AddBinding(Handle acceptor, const char *ipAddress, unsigned short port);
            NETWORK_API bool __stdcall AddBinding(Handle acceptor, const char *ipAddress, unsigned short port, bool reuse);
            NETWORK_API bool __stdcall RemoveBinding(Handle acceptor, const char *ipAddress, unsigned short port);
            NETWORK_API bool __stdcall ClearBindings(Handle acceptor);

            NETWORK_API ActiveLinkList::Handle __stdcall LockActiveLinks(Handle acceptor);
            NETWORK_API bool __stdcall UnlockActiveLinks(Handle acceptor);

            NETWORK_API bool __stdcall SetOnAccepted(Handle acceptor, const Event &callback, void *context);
            NETWORK_API bool __stdcall SetOnReceived(Handle acceptor, const Event &callback, void *context);
            NETWORK_API bool __stdcall SetOnClosed(Handle acceptor, const Event &callback, void *context);
        }
    }
}

#endif
